package com.thinkgem.jeesite.config;

import com.opensymphony.sitemesh.webapp.SiteMeshFilter;
import com.thinkgem.jeesite.common.servlet.ValidateCodeServlet;
import com.thinkgem.jeesite.modules.sys.listener.WebContextListener;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.boot.context.embedded.ServletListenerRegistrationBean;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.web.filter.DelegatingFilterProxy;

@Configuration
@ComponentScan(basePackages = "com.thinkgem.jeesite")
@ImportResource({"classpath*:/spring-context*.xml", "classpath*:/spring-mvc*.xml",})
public class WebConfig {
    @Bean
    public ServletRegistrationBean ValidateCodeServlet() {
        ServletRegistrationBean registration = new ServletRegistrationBean(new ValidateCodeServlet());
        registration.addUrlMappings("/servlet/validateCodeServlet");
        return registration;
    }
//
//    @Bean
//    public FilterRegistrationBean delegatingFilterProxy() {
//        FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
//        filterRegistration.setFilter(new DelegatingFilterProxy("shiroFilter"));
//        filterRegistration.addInitParameter("targetFilterLifecycle", "true");
//        filterRegistration.setEnabled(true);
//        filterRegistration.addUrlPatterns("/*");
//        return filterRegistration;
//    }

    @Bean
    public FilterRegistrationBean testFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean(new SiteMeshFilter());
        registration.addUrlPatterns("/a/*", "/f/*");
        return registration;
    }

//    @Bean
//    public ServletListenerRegistrationBean<WebContextListener> testListenerRegistration() {
//        ServletListenerRegistrationBean<WebContextListener> registration = new ServletListenerRegistrationBean<WebContextListener>(new WebContextListener());
//        return registration;
//    }
}
